<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="_static_resource/css/xadmin/font.css">
    <link rel="stylesheet" href="_static_resource/css/xadmin/xadmin.css">
    <link rel="stylesheet" href="_static_resource/css/xadmin/theme12.min.css">
    <link rel="stylesheet" href="_static_resource/ueditor/utf8-php/themes/default/css/ueditor.css" />
    <link rel="stylesheet" href="_static_resource/css/xadmin/theme5.css">
    <script src="_static_resource/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="_static_resource/js/xadmin/xadmin.js"></script>
    <script src="_static_resource/ueditor/utf8-php/ueditor.config.js"></script>
    <script src="_static_resource/ueditor/utf8-php/ueditor.all.min.js"></script>
    <script src="_static_resource/ueditor/utf8-php/lang/zh-cn/zh-cn.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    <script type="text/javascript">

    </script>
</head>
<style>
    div#editor {
        position: relative;
        left: 45px;
    }

    a.tags {
        height: 30px;
        line-height: 30px;
        position: relative;
        top: 4px;
        background: rgba(204, 0, 0, 1);
        border-radius: 3px;
        padding: 3px 10px;
        color: #fff;
    }

    a.tag_active {
        background: #3f8822 !important;
    }
</style>

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <input type="hidden" name="topcate" id="topcate" value="<?php echo $cate['pid'];?>" />
                <div class="layui-form-item">
                    <label for="title" class="layui-form-label">
                        <span class="x-red">*</span>文章标题</label>
                    <div class="layui-input-inline">
                        <input type="text" id="title" name="title" required="" lay-verify="required" autocomplete="off"
                            class="layui-input"></div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="desc" class="layui-form-label">文章描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="issue_time" class="layui-form-label">
                        <span class="x-red">*</span>默认发布时间</label>
                    <div class="layui-input-inline">
                        <input type="text" id="issue_time" name="issue_time" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="cate" class="layui-form-label">
                        <span class="x-red">*</span>内容分类</label>
                    <div class="layui-input-inline">
                        <select id="cate" name="cate" class="valid">
                            <!-- <option value="{$cate.navigate_id}">{$cate.navigate_name}</option> -->
                            {volist name='catelst' id='catelst'}
                            {if condition="$cate.navigate_id eq $catelst.navigate_id"}
                            <option value="{$catelst.navigate_id}" selected="selected">{$catelst.navigate_name}</option>
                            {else/}
                            <option value="{$catelst.navigate_id}">{$catelst.navigate_name}</option>
                            {/if}
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="clicktime" class="layui-form-label">
                        <span class="x-red">*</span>默认点击数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="clicktime" name="clicktime" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="default_like" class="layui-form-label">
                        <span class="x-red">*</span>默认赞数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="default_like" name="default_like" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="default_hate" class="layui-form-label">
                        <span class="x-red">*</span>默认踩数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="default_hate" name="default_hate" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="current_sort" class="layui-form-label">
                        <span class="x-red">*</span>当前排序</label>
                    <div class="layui-input-inline">
                        <input type="text" id="current_sort" name="current_sort" required="" lay-verify="required"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="author" class="layui-form-label">
                        <span class="x-red">*</span>作者</label>
                    <div class="layui-input-inline">
                        <input type="text" id="author" name="author" required="" value="admin" readonly
                            lay-verify="required" autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="author" class="layui-form-label">
                        <span class="x-red"></span>标签选择</label>
                    <div class="layui-input-inline" style="width: auto;">
                        {volist name="tags" id="tags"}
                        <a href="javascript:void(0)" class="tags" tags-id="{$tags.tag_id}">{$tags.tag_name}</a>
                        {/volist}
                    </div>
                </div>
                <div class="layui-form-item">
                    <!--<label class="layui-form-label">新闻正文</label>-->
                    <script id="editor"></script>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="add" lay-submit="">提交审核</button>
                    <button class="layui-btn" lay-filter="add" lay-submit="">发布</button>
                </div>
				<input type="hidden" id="tagString" name="tagString" hidden />
            </form>
        </div>
    </div>
    <!-- 默认Input -->
    <input type="hidden" id="defaultcate" id="defaultcate" value="{$cate.navigate_id}">
    <!-- 默认Input -->
    <script src="_static_resource/js/jquery.min.js"></script>
    <script>
        var ue = UE.getEditor('editor', {    //content为要编辑的textarea的id
            initialFrameWidth: 950,   //初始化宽度
            initialFrameHeight: 380,   //初始化高度
        });
        let tag = [];
        $(document).ready(function () {
            let defaultcate = $("input#defaultcate").val();
            $(document).on('click', 'a.tags', function () {
                if (!$(this).hasClass('tag_active')) {
                    $(this).addClass('tag_active');
                } else {
                    $(this).removeClass('tag_active');
                }
                let tagid = [];
                $('a.tag_active').each(function () {
                    tagid.push($(this).attr('tags-id'));
                })
                tag = tagid;
				$("input#tagString").val(tag.toString());
            })
        })
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //日期时间选择器
            laydate.render({
                elem: '#issue_time',
                type: 'datetime'
            });
        });
    </script>
    <script>
        layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;
                //自定义验证规则
                form.verify({
                    nikename: function (value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function (value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

                //监听提交
                form.on('submit(add)',
                    function (data) {
                        // var content = ue.getContent();
						var formdata = new FormData($("form")[0]);
                        $.ajax({
                            type: 'post',
                            url: '{:url("/webadmin/Knowledge/insertitem")}',
							data: formdata,
							cache : false,
                            dataType: 'json',
							processData : false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
							contentType : false, // 不设置Content-type请求头
                            success: function (ret) {
                                console.log(ret);
                            },
                            error: function (e) {
                                console.log(e);
                            }
                        })
                        //发异步，把数据提交给php
                        // layer.alert("增加成功", {
                        //     icon: 6
                        // },
                        // function () {
                        //     // 获得frame索引
                        //     var index = parent.layer.getFrameIndex(window.name);
                        //     //关闭当前frame
                        //     parent.layer.close(index);
                        // });
                        return false;
                    });

            });
    </script>
</body>

</html>